package club.zhcs.task.module;

import java.io.IOException;

import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.lang.random.R;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.SetupBy;
import org.nutz.mvc.ioc.provider.ComboIocProvider;

import club.zhcs.task.init.Init;

import com.dgj.nutz.module.base.AbstractBaseModule;
import com.dgj.utils.entries.Result;

@Modules(scanPackage = true)
@IocBy(type = ComboIocProvider.class, args = { "*org.nutz.ioc.loader.json.JsonLoader", "conf", "*org.nutz.ioc.loader.annotation.AnnotationIocLoader", "club.zhcs", "com.dgj" })
@Ok("json")
@Fail("http:500")
@SetupBy(Init.class)
public class MainModule extends AbstractBaseModule {
	@Inject
	Dao dao;

	@Override
	public String _getNameSpace() {
		return "main";
	}

	@At
	public Result hello() {
		return Result.success().addData("mysql", dao.meta());
	}

	@At
	@Ok("void")
	public void test() throws IOException {
		int i = R.random(10, 100);
		if (i > 60) {
			Mvcs.getResp().getWriter().write("ok");
			return;
		}
		Mvcs.getResp().getWriter().write("fail");
	}
}
